﻿using AutoMapper;
using B.S.BasicData.Domain;
using B.S.BasicData.ErrorCode;
using B.S.BasicData.Infrastructure.Interfance;
using B.S.BasicData.Read.Apilication.Common.Role;
using B.S.BasicData.Read.DTOS;
using MediatR;

namespace B.S.BasicData.Read.Apilication.Handler.Role
{
    public class TreeRoleHandler : IRequestHandler<TreeRoleCommon, ApiResult<List<RoleDTO>>>
    {
        private readonly IBaseRepository<RoleModel> roleRepo;
        private readonly IMapper mapper;

        public TreeRoleHandler(IBaseRepository<RoleModel> roleRepo,IMapper mapper)
        {
            this.roleRepo = roleRepo;
            this.mapper = mapper;
        }
        public Task<ApiResult<List<RoleDTO>>> Handle(TreeRoleCommon request, CancellationToken cancellationToken)
        {
            ApiResult<List<RoleDTO>> res = new ApiResult<List<RoleDTO>>();


            var info = roleRepo.GetAll().Where(x=>x.IsDeleted==false).Select(x=>new RoleDTO()
            {
                RoleId = x.RoleId,
                RoleName = x.RoleName,
            }).ToList();

            res.Message = "角色树形查询成功";
            res.Code=ApiEnum.Success;
            res.Data = info;
            return Task.FromResult(res);
        }

       
    }
}
